library OfficerMunitionsCount initializer init requires LegacySystem


	private function MunitionsCountConditions takes nothing returns boolean
		return GetSpellAbilityId()=='A02T'
	endfunction

	private function MunitionsCount takes nothing returns nothing
		local integer i = 1
		local force f = GetPlayersMatching(Condition(function UnitSelected))
		local player p
		call DisplayTimedTextToForce( f, 20.0, " " )
		call DisplayTimedTextToForce( f, 20.0, "|cfff3ad00Munitions Count - Echo Company|r" )
		loop
			exitwhen i>udg_Players
			set p = ConvertedPlayer(udg_Sorted[i])
			if IsUnitType(udg_Hero[udg_Sorted[i]],UNIT_TYPE_HERO)==true then
				call DisplayTimedTextToForce( f, 20.0, udg_Pcolors[udg_Sorted[i]] + /*
				*/  GetPlayerName(p) + "|r : " + /*
				*/  I2S(GetPrimaryAmmoRounds(p)) + " / " + I2S(GetPrimaryAmmoMagazines(p)) )
			endif
			set i=i+1
		endloop
		call DestroyForce(f)
		set f = null
	endfunction

	private function init takes nothing returns nothing
		local trigger t
		set t = CreateTrigger()
		call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT  )
		call TriggerAddCondition( t, Condition( function MunitionsCountConditions ) )
		call TriggerAddAction(t,function MunitionsCount)
	endfunction

endlibrary